package com.copractice.data.entity.feedback;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ToStringBuilder;

import com.copractice.data.entity.PersistentObject;
import com.copractice.data.entity.answer.Answer;

/**
 * Represents entity which contains different score values between feedback and question answers: helpfulness, rating.
 *
 * @author Dmitry Churbanov (dmitry.churbanov@gmail.com)
 * @version 1.0 04/15/2009
 */
@Entity
@Table(name = "FEEDBACK_ANSWER")
@SuppressWarnings("serial")
public class FeedbackAnswer extends PersistentObject {
    
    private Integer overallrating;
    
    /**
     * rating of a feedback
     */
    private Double rating;
    
    /**
     * helpfulness of a feedback for a particular answer
     */
    private Double helpfulness;
    
    /**
     * answers of a question to which the feedback is related 
     */
    private Answer answer;
    
    /**
     * feedback which helpfulness and rating score for a particular answer 
     * are contained here  
     */
    private UsersFeedback feedback;

    private Integer numberOfUserRating;
    
    private Integer numberOfHelpfulness;
    
    /**
     * @see edu.vt.intelligenttutor.data.entity.PersistentObject#getId()
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Override
    public Long getId() {
        return super.getId();
    }      
    
    @Column(name = "NUM_OF_RATING")
    public Integer getNumberOfUserRating()
    {
        return numberOfUserRating;
    }

    public void setNumberOfUserRating(Integer numberOfUserRating)
    {
        this.numberOfUserRating = numberOfUserRating;
    }

    @Column(name = "NUM_OF_HELPFULNESS")
    public Integer getNumberOfHelpfulness()
    {
        return numberOfHelpfulness;
    }

    public void setNumberOfHelpfulness(Integer numberOfHelpfulness)
    {
        this.numberOfHelpfulness = numberOfHelpfulness;
    }
    
    public Integer getOverallrating()
    {
        return overallrating;
    }

    public void setOverallrating(Integer overallrating)
    {
        this.overallrating = overallrating;
    }   

    /**
     * Returns rating value
     *
     * @return rating value
     */
    @Column(name = "RATING")
    public Double getRating() {
        return rating;
    }

    /**
     * Sets rating value
     *
     * @param rating the <code>Double</code> to be set as rating value
     */
    public void setRating(Double rating) {
        this.rating = rating;
    }

    /**
     * Returns helpfulness value
     *
     * @return helpfulness value
     */
    @Column(name = "HELPFULNESS")
    public Double getHelpfulness() {
        return helpfulness;
    }

    /**
     * Set helpfulness value
     *
     * @param helpfulness the <code>Double</code> to be set as helpfulness value
     */
    public void setHelpfulness(Double helpfulness) {
        this.helpfulness = helpfulness;
    }

    /**
     * Returns the answer which this feedback is rated
     *
     * @return the <code>Answer</code> this feedback is rated
     */
    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.MERGE})
    @JoinColumn(name="ANSWER_ID")
    public Answer getAnswer() {
        return answer;
    }

    /**
     * Sets the answer which this feedback is rated
     * 
     * @param answer the <code>Answer</code> this feedback is rated
     */
    public void setAnswer(Answer answer) {
        this.answer = answer;
    }

    /**
     * Returns the feedback
     * 
     * @return the <code>UsersFeedback</code>
     */
    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.MERGE})
    @JoinColumn(name="FEEDBACK_ID")    
    public UsersFeedback getFeedback() {
        return feedback;
    }

    /**
     * Sets the feedback
     * 
     * @param feedback the <code>UsersFeedback</code>
     */
    public void setFeedback(UsersFeedback feedback) {
        this.feedback = feedback;
    }    
    
    /**
     * Returns a string representation of the entity.
     * 
     * @return a string representation of the entity.
     */
    @Override
    public String toString() {
        return new ToStringBuilder(this)
                   .append("id", getId())
                   .append("rating", rating)
                   .append("helpfulness", helpfulness)
                   .append("answer", answer)
                   .append("feedback", feedback)
                   .toString();
    }    
    
}
